{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "lovely-andorra",
   "metadata": {},
   "outputs": [],
   "source": [
    "from code.ftquoteapi import quoteapi as quote\n",
    "import imp\n",
    "from futu import *\n",
    "#imp.reload(quoteapi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "furnished-sword",
   "metadata": {},
   "outputs": [],
   "source": [
    "context = quote()"
   ]
  },
  {
   "cell_type": "raw",
   "id": "naked-criminal",
   "metadata": {},
   "source": [
    "中文\t英文\n",
    "全部\tAll\n",
    "沪深\tCN\n",
    "港股\tHK\n",
    "美股\tUS\n",
    "期权\tOptions\n",
    "港股期权\tHK options\n",
    "美股期权\tUS options\n",
    "特别关注\tStarred\n",
    "期货\tFutures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "global-plaza",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-03-01 11:45:45,413 [open_context_base.py] _socket_reconnect_and_wait_ready:255: Start connecting: host=127.0.0.1; port=11111;\n",
      "2021-03-01 11:45:45,416 [open_context_base.py] on_connected:344: Connected : conn_id=1; \n",
      "2021-03-01 11:45:45,420 [open_context_base.py] _handle_init_connect:445: InitConnect ok: conn_id=1; info={'server_version': 500, 'login_user_id': 716900, 'conn_id': 6771998858079501381, 'conn_key': 'BEBB3025D892349F', 'conn_iv': '2C531ED40856165C', 'keep_alive_interval': 10, 'is_encrypt': False};\n",
      "2021-03-01 11:45:45,838 [network_manager.py] work:366: Close: conn_id=1\n"
     ]
    }
   ],
   "source": [
    "context.init_context()\n",
    "ret, df = context.get_user_security_group()\n",
    "context.closecontext()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "matched-recorder",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>group_name</th>\n",
       "      <th>group_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>新加坡</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>债券</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>期权</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>期货</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>港股期权</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>特别关注</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>美股期权</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>美股</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>港股</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>沪深</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>全部</td>\n",
       "      <td>SYSTEM</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   group_name group_type\n",
       "0         新加坡     SYSTEM\n",
       "1          债券     SYSTEM\n",
       "2          期权     SYSTEM\n",
       "3          期货     SYSTEM\n",
       "4        港股期权     SYSTEM\n",
       "5        特别关注     SYSTEM\n",
       "6        美股期权     SYSTEM\n",
       "7          美股     SYSTEM\n",
       "8          港股     SYSTEM\n",
       "9          沪深     SYSTEM\n",
       "10         全部     SYSTEM"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "tribal-letters",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-03-01 11:50:42,171 [open_context_base.py] _socket_reconnect_and_wait_ready:255: Start connecting: host=127.0.0.1; port=11111;\n",
      "2021-03-01 11:50:42,174 [open_context_base.py] on_connected:344: Connected : conn_id=8; \n",
      "2021-03-01 11:50:42,177 [open_context_base.py] _handle_init_connect:445: InitConnect ok: conn_id=8; info={'server_version': 500, 'login_user_id': 716900, 'conn_id': 6772000102761794087, 'conn_key': '618CF526D8922806', 'conn_iv': '68DA2C7348565685', 'keep_alive_interval': 10, 'is_encrypt': False};\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   group_name group_type\n",
      "0         新加坡     SYSTEM\n",
      "1          债券     SYSTEM\n",
      "2          期权     SYSTEM\n",
      "3          期货     SYSTEM\n",
      "4        港股期权     SYSTEM\n",
      "5        特别关注     SYSTEM\n",
      "6        美股期权     SYSTEM\n",
      "7          美股     SYSTEM\n",
      "8          港股     SYSTEM\n",
      "9          沪深     SYSTEM\n",
      "10         全部     SYSTEM\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-03-01 11:50:42,192 [network_manager.py] work:366: Close: conn_id=8\n"
     ]
    }
   ],
   "source": [
    "context.init_context()\n",
    "ret, df = context.get_user_security_group(UserSecurityGroupType.SYSTEM)  #NONE  CUSTOM  SYSTEM\n",
    "print(df)\n",
    "context.closecontext()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "annoying-merchant",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-03-01 11:53:29,623 [open_context_base.py] _socket_reconnect_and_wait_ready:255: Start connecting: host=127.0.0.1; port=11111;\n",
      "2021-03-01 11:53:29,626 [open_context_base.py] on_connected:344: Connected : conn_id=10; \n",
      "2021-03-01 11:53:29,630 [open_context_base.py] _handle_init_connect:445: InitConnect ok: conn_id=10; info={'server_version': 500, 'login_user_id': 716900, 'conn_id': 6772000805112484597, 'conn_key': '8A0FF527D8928CD5', 'conn_iv': 'A6489BCD6F566693', 'keep_alive_interval': 10, 'is_encrypt': False};\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                   code                 name  lot_size stock_type  \\\n",
      "0   HK.TCH210330C680000   腾讯 210330 680.00 购       100       DRVT   \n",
      "1   HK.TCH210330C720000   腾讯 210330 720.00 购       100       DRVT   \n",
      "2              HK.53321           中芯法兴一九牛E.C      2500    WARRANT   \n",
      "3              HK.01970              IMAX 中国       100      STOCK   \n",
      "4              HK.02318                 中国平安       500      STOCK   \n",
      "5              HK.03968                 招商银行       500      STOCK   \n",
      "6              HK.06969                思摩尔国际      1000      STOCK   \n",
      "7    HK.SMC210528C28000  中芯国际 210528 28.00 购      2500       DRVT   \n",
      "8              HK.23411           华虹摩通一八购A.C      5000    WARRANT   \n",
      "9              HK.01024                 快手-W       100      STOCK   \n",
      "10             HK.01347                华虹半导体      1000      STOCK   \n",
      "11             HK.09922                  九毛九      1000      STOCK   \n",
      "12             HK.00305                 五菱汽车     10000      STOCK   \n",
      "13             HK.03888                 金山软件      1000      STOCK   \n",
      "14             HK.02382               舜宇光学科技       100      STOCK   \n",
      "15             HK.00499                 青岛控股      2000      STOCK   \n",
      "16             HK.27649           中芯汇丰一乙购B.C      2500    WARRANT   \n",
      "17             HK.16031           中芯汇丰一乙购A.C     25000    WARRANT   \n",
      "18             HK.00175                 吉利汽车      1000      STOCK   \n",
      "19             HK.00981                 中芯国际       500      STOCK   \n",
      "20             HK.09992                 泡泡玛特       200      STOCK   \n",
      "21             HK.06666                 恒大物业       500      STOCK   \n",
      "22             HK.02899                 紫金矿业      2000      STOCK   \n",
      "23             HK.01288                 农业银行      1000      STOCK   \n",
      "24             HK.01211                比亚迪股份       500      STOCK   \n",
      "25             HK.00778               置富产业信托      1000        ETF   \n",
      "26             HK.03690                 美团-W       100      STOCK   \n",
      "27             HK.03913                 合景悠活      1000      STOCK   \n",
      "28             HK.09633                 农夫山泉       200      STOCK   \n",
      "29             HK.02333                 长城汽车       500      STOCK   \n",
      "30             HK.00388                香港交易所       100      STOCK   \n",
      "31             HK.00700                 腾讯控股       100      STOCK   \n",
      "\n",
      "   stock_child_type stock_owner option_type strike_time strike_price  \\\n",
      "0               N/A    HK.00700        CALL  2021-03-30          680   \n",
      "1               N/A    HK.00700        CALL  2021-03-30          720   \n",
      "2              BULL    HK.00981                                  N/A   \n",
      "3               N/A                                              N/A   \n",
      "4               N/A                                              N/A   \n",
      "5               N/A                                              N/A   \n",
      "6               N/A                                              N/A   \n",
      "7               N/A    HK.00981        CALL  2021-05-28           28   \n",
      "8              CALL    HK.01347                                  N/A   \n",
      "9               N/A                                              N/A   \n",
      "10              N/A                                              N/A   \n",
      "11              N/A                                              N/A   \n",
      "12              N/A                                              N/A   \n",
      "13              N/A                                              N/A   \n",
      "14              N/A                                              N/A   \n",
      "15              N/A                                              N/A   \n",
      "16             CALL    HK.00981                                  N/A   \n",
      "17             CALL    HK.00981                                  N/A   \n",
      "18              N/A                                              N/A   \n",
      "19              N/A                                              N/A   \n",
      "20              N/A                                              N/A   \n",
      "21              N/A                                              N/A   \n",
      "22              N/A                                              N/A   \n",
      "23              N/A                                              N/A   \n",
      "24              N/A                                              N/A   \n",
      "25              N/A                                              N/A   \n",
      "26              N/A                                              N/A   \n",
      "27              N/A                                              N/A   \n",
      "28              N/A                                              N/A   \n",
      "29              N/A                                              N/A   \n",
      "30              N/A                                              N/A   \n",
      "31              N/A                                              N/A   \n",
      "\n",
      "   suspension listing_date        stock_id  delisting  main_contract  \\\n",
      "0       False          N/A        80156795      False          False   \n",
      "1       False          N/A        80156890      False          False   \n",
      "2         N/A   2021-02-11  80169859600457      False          False   \n",
      "3         N/A   2015-10-08  71790378354610      False          False   \n",
      "4         N/A   2004-06-24  54082228193550      False          False   \n",
      "5         N/A   2006-09-22  57604101377920      False          False   \n",
      "6         N/A   2020-07-10  79203491912505      False          False   \n",
      "7       False          N/A        80219044      False          False   \n",
      "8         N/A   2021-01-26  80092550159219      False          False   \n",
      "9         N/A   2021-02-05  80109730006016      False          False   \n",
      "10        N/A   2014-10-15  70252780062019      False          False   \n",
      "11        N/A   2020-01-15  78421807867586      False          False   \n",
      "12        N/A   1992-11-23  35910221562161      False          False   \n",
      "13        N/A   2007-10-09  59244778884912      False          False   \n",
      "14        N/A   2007-06-15  58746562677070      False          False   \n",
      "15        N/A   1988-07-22  29102698398195      False          False   \n",
      "16        N/A   2020-09-22  79551384284161      False          False   \n",
      "17        N/A   2020-07-10  79224966758047      False          False   \n",
      "18        N/A   1973-02-23   4930622455983      False          False   \n",
      "19        N/A   2004-03-18  53661321397205      False          False   \n",
      "20        N/A   2020-12-11  79869211846408      False          False   \n",
      "21        N/A   2020-12-02  79834852104714      False          False   \n",
      "22        N/A   2003-12-23  53291954211667      False          False   \n",
      "23        N/A   2010-07-16  63586990818568      False          False   \n",
      "24        N/A   2002-07-31  51101520889019      False          False   \n",
      "25        N/A   2010-04-20  63213328663306      False          False   \n",
      "26        N/A   2018-09-20  76364518526570      False          False   \n",
      "27        N/A   2020-10-30  79684528246601      False          False   \n",
      "28        N/A   2020-09-08  79448305051041      False          False   \n",
      "29        N/A   2003-12-15  53257594472733      False          False   \n",
      "30        N/A   2000-06-27  47820165874052      False          False   \n",
      "31        N/A   2004-06-16  54047868453564      False          False   \n",
      "\n",
      "   last_trade_time  \n",
      "0                   \n",
      "1                   \n",
      "2                   \n",
      "3                   \n",
      "4                   \n",
      "5                   \n",
      "6                   \n",
      "7                   \n",
      "8                   \n",
      "9                   \n",
      "10                  \n",
      "11                  \n",
      "12                  \n",
      "13                  \n",
      "14                  \n",
      "15                  \n",
      "16                  \n",
      "17                  \n",
      "18                  \n",
      "19                  \n",
      "20                  \n",
      "21                  \n",
      "22                  \n",
      "23                  \n",
      "24                  \n",
      "25                  \n",
      "26                  \n",
      "27                  \n",
      "28                  \n",
      "29                  \n",
      "30                  \n",
      "31                  \n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-03-01 11:53:30,111 [network_manager.py] work:366: Close: conn_id=10\n"
     ]
    }
   ],
   "source": [
    "context.init_context()\n",
    "ret, df = context.get_user_security('港股')\n",
    "print(df)\n",
    "context.closecontext()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "religious-mystery",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
